package asruby.runtime {

import asruby.asupport.RuntimeHelpers;
import asruby.lang.RubyClass;

public class Dispatcher {
/*     private static class DefaultDispatcher extends Dispatcher {
        public  function DefaultDispatcher(){
            switchTable = new byte[0];
        }
        
        public IRubyObject callMethod(ThreadContext context, IRubyObject self, RubyClass rubyclass, int methodIndex, String name,
                IRubyObject[] args, CallType callType, Block block) {
            try {
                return RuntimeHelpers.invokeAs(context, rubyclass, self, name, args, callType, block);
            } catch (soe:StackOverflowError) {
                throw context.getRuntime().newSystemStackError("stack level too deep");
            }
        }
    }; */
    
    public static var DEFAULT_DISPATCHER: Dispatcher =  new Dispatcher();
    
    protected  var switchTable:Array = new Array();
    
    public function callMethod(context:ThreadContext, self:IRubyObject, rubyclass:RubyClass,  methodIndex:int,  name:String,
            args:Array,  callType:CallType,  block:Block):IRubyObject {
      		try {
                return RuntimeHelpers.invokeAs(context, rubyclass, self, name, args, callType, block);
            } catch (soe:Error) {
                throw new Error("stack level too deep");
            }
            return null;     	
    }
    
    public  function clearIndex(index:int):void{
        if (index >= switchTable.length) return;
        
        switchTable[index] = 0;
    }
}
}